package com._21cn.cms.site.web.validator;

import com._21cn.cms.site.entity.Site;
import com._21cn.framework.utils.StringUtil;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

@Component("siteValidator")
public class SiteValidator implements Validator {

    public boolean supports(Class<?> clazz) {
        return Site.class.equals( clazz );
    }

    public void validate(Object target, Errors errors) {
        Site obj = (Site)target;
        if( obj.getPath() == null || StringUtil.isEmpty( obj.getPath() ) ){
            errors.rejectValue( "path", "error.path", "path是必需的" );
        }
        if( obj.getCode() == null || StringUtil.isEmpty( obj.getCode() ) ){
            errors.rejectValue( "path", "error.code", "code是必需的" );
        }
    }
}